//% color="#0051a4" iconWidth=50 iconHeight=40
namespace XKG_wifi{
    //% block="行空板wifi:ip地址,输入ssid:[ssid],password:[password]" blockType="command"
    //% ssid.shadow="normal" ssid.defl="wifi名称"
    //% password.shadow="normal" password.defl="wifi密码"
    export function XKB_wifi(parameter: any, block: any) {
        let ssid=parameter.ssid.code
        let password=parameter.password.code
        Generator.addImport(`import requests\nimport json`)
        Generator.addCode(`
wifi_start=0
data_str={
    "ssid":'${ssid}',
    "password":'${password}'
}
while not ((wifi_start > 1)):   
    url="http://10.1.2.3/wifi/connect"
    my_variable = requests.get("http://10.1.2.3/wifi/scan")#扫描wifi
    my_variable = requests.get(url=url,data=data_str) # ssid和password后面改为需要连接的wifi名字密码
    my_variable = requests.get("http://10.1.2.3/wifi/status")
    wifidata = my_variable.json()
    wifi_start=len(wifidata['ip']) 
        `)

    } 
    //% block="行空板wif:ip地址" blockType="reporter"
    export function XKB_IP(parameter: any, block: any) {
        Generator.addCode(`wifidata['ip']`)

    } 
    
}

